﻿@model Course

@{
    ViewBag.Title = string.Format("Redigér {0}", Model.Name);
}

<div class="page-header">
    <h1><span class="glyphicon glyphicon-globe"></span> @ViewBag.Title</h1>
</div>

@if (!ViewData.ModelState.IsValid)
{
    <div class="alert alert-danger alert-dismissable">
        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
        @Html.ValidationSummary("", new { @style = "color: #fff;" })
    </div>
}

@using (Html.BeginForm("Edit", "Course", FormMethod.Post, new { role = "form", @class = "form-horizontal" }))
{
    <div class="form-group">
        <label for="Name" class="col-sm-2 control-label">navn</label>
        <div class="col-sm-10">
            <input type="text" id="Name" name="Name" class="form-control" required placeholder="klubbens navn" value="@Model.Name">
        </div>
    </div>
    <div class="form-group">
        <label for="Address" class="col-sm-2 control-label">adresse</label>
        <div class="col-sm-10">
            <input type="text" id="Address" name="Address" class="form-control" required placeholder="" value="@Model.Address">
        </div>
    </div>

    <div class="form-group">
        <label for="ZipCode" class="col-sm-2 control-label">postnr.</label>
        <div class="col-sm-4">
            <input type="text" id="ZipCode" name="ZipCode" class="form-control" required placeholder="" value="@Model.ZipCode">
        </div>
    </div>

    <div class="form-group">
        <label for="City" class="col-sm-2 control-label">by</label>
        <div class="col-sm-10">
            <input type="text" id="City" name="City" class="form-control" required placeholder="" value="@Model.City">
        </div>
    </div>

    <div class="form-group">
        <label for="CountryCodeISO3166Alpha2" class="col-sm-2 control-label">landekode</label>
        <div class="col-sm-10">
            <input type="text" id="CountryCodeISO3166Alpha2" name="CountryCodeISO3166Alpha2" class="form-control" required placeholder="DK,DE, ES, PT o.l." value="@Model.CountryCodeISO3166Alpha2" size="2" maxlength="2" />
        </div>
    </div>
        
    @Html.EditorFor(x=>x.Lat)
    
    @Html.EditorFor(x=>x.Lng)
    
    <div class="form-group">
        <label class="col-sm-2 control-label"></label>
        <div class="col-sm-8">
            <button type="submit" class="btn btn-default">gem</button>
        </div>
    </div>
}

@section Scripts {
@Scripts.Render("~/bundles/globalize")
    @Scripts.Render("~/bundles/jqueryval")
    @Scripts.Render("~/Scripts/_thecup_editing.js")

    <script>
        // course address
        var geoAddress = "@Html.Raw(Model.GeoAddress)";

        // elements
        var lng = document.getElementById('Lng');
        var lat = document.getElementById('Lat');
        
        if (lng.value === "" && lat.value === "") {
            theCup.getGeoLocForAddress(geoAddress, success);
        }

        function success(data){
            // data
            var result = data.results[0];
            var loc = result.geometry.location;
            
            // set it
            if (lat.value === "" && lng.value === "") {
                lat.value = loc.lat;
                lng.value = loc.lng;
            }
        }
    </script>
}
